package com.xq.jltx.ndkoperatorjava;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.xq.jltx.bean.DataBean;
import com.xq.jltx.javajni.DataFieldProvider;
import com.xq.jltx.javajni.DataObjProvider;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView textView;
    private Button btn1;
    private Button btn2;
    private Button btn3;
    private Button btn4;
    private Button btn5;
    private Button btn6;
    private Button btn7;
    private Button btn8;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = (TextView) findViewById(R.id.tv);
        textView.setText("结果显示");
        btn1 = (Button) findViewById(R.id.btn1);
        btn1.setOnClickListener(this);
        btn2 = (Button) findViewById(R.id.btn2);
        btn2.setOnClickListener(this);
        btn3 = (Button) findViewById(R.id.btn3);
        btn3.setOnClickListener(this);
        btn4 = (Button) findViewById(R.id.btn4);
        btn4.setOnClickListener(this);
        btn5 = (Button) findViewById(R.id.btn5);
        btn5.setOnClickListener(this);
        btn6 = (Button) findViewById(R.id.btn6);
        btn6.setOnClickListener(this);
        btn7 = (Button) findViewById(R.id.btn7);
        btn7.setOnClickListener(this);
        btn8 = (Button) findViewById(R.id.btn8);
        btn8.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn1:
                DataFieldProvider provider = new DataFieldProvider();
                provider.onNativeSetName();
                textView.setText(provider.getName());
                break;
            case R.id.btn2:
                DataFieldProvider provider1 = new DataFieldProvider();
                provider1.onNativeSetStaticName();
                textView.setText(DataFieldProvider.getsName());
                break;
            case R.id.btn3:
                DataBean dataBean = DataObjProvider.getDataBeanInfo();
                textView.setText(dataBean != null ? dataBean.toString() : "dataBean == null");
                break;
            case R.id.btn4:
                DataBean dataBean1 = new DataBean("I am jltxseo");
                dataBean1.setDataId(789633333);
                DataObjProvider.setDataBeanInfo(dataBean1);
                textView.setText("对比ndk.out.c为tag的log=>" + dataBean1.toString());
                break;
            case R.id.btn5:
                ArrayList<DataBean> dataList = DataObjProvider.getListDataBeans();
                textView.setText(dataList != null ? "list大小:"+ dataList.size() : "dataList == null or dataList size == 0");
                break;
            case R.id.btn6:
                textView.setText(DataObjProvider.testLocalRefFromJNI());
                break;
            case R.id.btn7:
                textView.setText(DataObjProvider.testGlobalRefFromJNI());
                break;
            case R.id.btn8:
                textView.setText(DataObjProvider.testWeakRefFromJNI());
                break;
            default:
                break;
        }
    }
}
